package com.xl.basic.job;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xl.dao.domain.XlVisitLog;
import com.xl.dao.mapper.XlVisitLogMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author 钟勇
 * Create in 2024/1/23 11:27
 */
@Component
@RequiredArgsConstructor
public class VisitLogJob {

    private final XlVisitLogMapper logMapper;

    /**
     * 每天1:00执行日志文件清除
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void cleanLog() {
        //删除超过一个月的数据
        logMapper.delete(new LambdaQueryWrapper<XlVisitLog>()
                .le(XlVisitLog::getBeginTime, LocalDateTime.now().minusMonths(1))
        );
    }
}
